package com.ice.delay.task.controller;

import com.ice.delay.task.core.model.DelayTaskDetail;
import com.ice.delay.task.service.DelayTaskDetailService;
import com.ice.delay.task.vo.req.DelayTaskDetailRetryVoReq;
import com.ice.delay.task.vo.req.DelayTaskDetailVoReq;
import com.ice.delay.task.vo.res.DelayTaskDetailVoRes;
import com.ice.framework.common.annotation.AutoResult;
import com.ice.framework.common.base.RPage;
import com.ice.framework.web.repeat.Idempotent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 延迟任务
 * @author wangwei
 * @Date 2022/4/26 14:25
 */
@RequestMapping("/task")
@Controller
public class DelayTaskDetailController {

    @Autowired
    private DelayTaskDetailService delayTaskDetailService;
    /**
     * 保存延迟任务
     * @Author wangwei
     * @Date 2022/5/7 
     */
    @AutoResult
    @ResponseBody
    @PostMapping("/createDelayTask")
    public void saveDelayTask(@RequestBody @Valid DelayTaskDetail delayTaskDetail) {
        delayTaskDetailService.saveDelayTask(delayTaskDetail);
    }

    @AutoResult
    @ResponseBody
    @PostMapping("/page")
    public RPage<DelayTaskDetailVoRes> page(@RequestBody RPage<DelayTaskDetailVoReq> page) {
        return delayTaskDetailService.pageDetail(page);
    }

    @AutoResult
    @ResponseBody
    @PostMapping("/findDetail")
    public DelayTaskDetailVoRes findDetail(@RequestBody DelayTaskDetailVoReq req) {
        return delayTaskDetailService.findDetail(req);
    }

    @AutoResult
    @ResponseBody
    @PostMapping("/retry")
    public void retry(@RequestBody @Valid DelayTaskDetailRetryVoReq req){
        delayTaskDetailService.retry(req);
    }

    @RequestMapping("/index")
    public String index(){
        return "/admin/task_delay_detail";
    }
}
